% Assumes data is already loaded, X, Y, Xtest exist

ratings = [1 2 4 5];

%% Train

% Use kernel
%k = @(x,x2) kernel_intersection(x, x2);
%[results.intersect, info, yhat] = kernel_liblinear(X, Y, Xtest, zeros(size(Xtest,1),1), k);


% Not using kernel

% Train word count data
B = 0.1;
[results, info, yhat] = lin_liblinear(X, Y, Xtest, zeros(size(Xtest,1),1), 7, B);

% Train title and helpful rating data
[results_th, info_th, yhat_th] = lin_liblinear(XhelpTitle, Y, ...
  XtesthelpTitle, zeros(size(Xtest,1),1), 7);


%% Calc expected values

% Word count EV
p = exp(info.vals);
p = bsxfun(@times, p, 1./sum(p,2));
yhatE = sum(bsxfun(@times, p, ratings),2);

% Title and helpful ratings EV
p_th = exp(info_th.vals);
p_th = bsxfun(@times, p_th, 1./sum(p_th,2));
yhatE_th = sum(bsxfun(@times, p_th, ratings),2);


%% Combine expected values from the two
yhatE_comb = (yhatE + yhatE_th) ./ 2;


%% Save predictions
save('-ascii', 'submit.txt', 'yhatE_comb');

